this.name      = "dredgerShip"; 
this.author    = "eric walch"; 
this.copyright   = "� 2008 Walch & Sabre & Little Bear"; 
this.description = "Script for dredger ship";
this.version   = "1.2";


this.shipSpawned = function()
{
    this.shuttles = Math.round(Math.sqrt(this.ship.mass)/2000); // 20 till 80
    this.dockedShuttles = 0
    this.ship.primaryRole = "dredgers"; // we need this name for the commodity.plist
    if(this.ship.displayName == this.ship.name)
        this.ship.displayName = expandDescription("[salvage_drone_gotit11] [salvage_drone_gotit12]")
}

this.checkLaunches = function()
{
    if(this.shuttles-- > 0) this.ship.reactToAIMessage("LAUNCH_SHUTTLE"); 
    else if(!this.waitForDocking){this.ship.reactToAIMessage("RESUME_FLIGHT");this.shuttles += this.dockedShuttles;}
}

this.dockingRequested = function()
{
	this.waitForDocking = true;
}

this.dockingComplete = function()
{
	this.waitForDocking = false;
}

this.launchFromPlanet= function()
{
	worldScripts.deep_space_dredger.dredgerWaitingShip = this.ship  // used as target by rising shuttles.
	var launchVector = this.ship.position.subtract(system.mainPlanet.position).direction()
	var launchSite = system.mainPlanet.position.add(launchVector.multiply(system.mainPlanet.radius + 2500))
	system.legacy_addShipsAtPrecisely("dredgershuttle_up", 8, "abs", launchSite)
	this.waitForDocking = true;
}

this.otherShipDocked = function(ship)
{
    if(ship.primaryRole == "dredgershuttle_up") this.dockedShuttles++;
}

this.startScanner = function()
{
	worldScripts.deep_space_dredger.startScanner(this.ship) // transfer this dredgers entity for messages.
}
// don't use repeating timers in shipscripts. Can lead to crashes.

this.shipDied = function(whom, why)
{
	log(this.name, this.ship.displayName + " was killed by: "+whom+" because of: "+why)
}
